package com.tsll.controller;

import com.tsll.annotation.MyLog;
import com.tsll.entity.User;
import com.tsll.service.impl.UserServiceImpl;
import com.tsll.vo.Result;
import com.tsll.vo.StaffVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserServiceImpl userService;

    /**
     * 查询用户的信息。
     *并且分页
     */
    @MyLog(businessName = "查询所有用户信息")
    @RequestMapping("/select/{current}/{pageSize}")
    public Result selectAll(@PathVariable Integer current, @PathVariable Integer pageSize, StaffVo staffVo){
        Result result = userService.selectAll(current, pageSize, staffVo);
        return result;
    }
    /**
     * 更新用户信息
     */
    @MyLog(businessName = "更新用户信息")
    @RequestMapping("/update")
    public Result updateAll(@RequestBody User user){
        int update = userService.update(user);
        return new Result(200,"修改成功",null);
    }
    /**
     * 根据提供的ID删除记录。
     *
     */
    @MyLog(businessName = "删除用户信息")
    @RequestMapping("/delete/{id}")
    public Result deleteAll(@PathVariable Integer id){
        int delete = userService.delete(id);
        return new Result(200,"删除成功",null);
    }
    /**
     * 请求映射路径为/insert的处理方法，用于插入用户信息。
     *
     */
    @MyLog(businessName = "添加用户信息")
    @RequestMapping("/insert")
    public Result insertAll(@RequestBody User user){
        userService.insertAll(user);
        return new Result(200,"添加成功",null);
    }

    @RequestMapping("/selectByCount/{no}")
    public Result selectByCount(@PathVariable String no) {
        return userService.selectByCount(no);
    }

    @RequestMapping("/login")
    public  Result login(@RequestBody User user){
        Result result = userService.login(user);
        return result;
    }
}
